package dlut.java;

import org.w3c.dom.ls.LSOutput;

import java.util.Scanner;

/**
 * 数组删除一个元素，长度为k的子数组的最大和
 */
public class Solusion {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();

        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int[] nums2 = new int[n+1];//前缀和数组
        for (int i = 1; i <= n; i++) {
            nums2[i] = nums2[i-1] + nums[i-1];
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i <= n - k; i++) {
            max = Math.max(max, nums2[k + i] - nums2[i]);
        }
        STree sTree = new STree(nums);
        for (int i = 0; i < n - k; i++) {
            int query = sTree.query(0, k);
            max = Math.max(max, nums2[k + i + 1] - nums2[i] - query);
        }
        System.out.println(max);
    }

    /**
     * 线段树
     */
    static class STree{
        private int[] data;//接收用户传进来的数组
        private int[] tree;//线段树
//        private Merger<E> merge;
        //初始化数组和线段树并构建线段树
        public STree(int[] arr) {

            data=new int[arr.length];//声明空间大小
            //给data填值
            for(int i=0;i<arr.length;i++){
                data[i]=arr[i];
            }
            //声明线段树空间大小
            tree=new int[arr.length * 2];
            //构建线段树
            buildSegmentTree(0,0,data.length-1);
        }
        //
        public  int query(int queryL,int queryR){
//            if(queryL<0||queryL>=data.length||queryR<0||
//                    queryR>=data.length||queryR<queryL){
//                throw new IllegalArgumentException("参数错误");
//            }
            return queryRange(0,0,data.length-1,queryL,queryR);

        }
        //执行真正的查询
        private int queryRange(int index,int l,int r,int queryL,int queryR){
            int result = 0 ;
            if(l==queryL&&r==queryR){
                return tree[index];
            }
            int left=leftChild(index);//根据index得到左孩子的索引赋给left
            int right=rightChild(index);//根据index得到右孩子的索引赋给right
            int mid=l+(r-l)/2;//中间边界
            if(queryL>=mid+1){
                result=queryRange(right,mid+1,r,queryL,queryR);
            }else if(queryR<=mid){
                result=queryRange(left,l,mid,queryL,queryR);
            }else{
                int a=queryRange(left,l,mid,queryL,mid);
                int b=queryRange(right,mid+1,r,mid+1,queryR);
                result=Math.min(a,b);
            }
            return result;
        }
        //左孩子的索引
        private int leftChild(int index){
            return 2*index+1;
        }
        //右孩子的索引
        private int rightChild(int index){
            return 2*index+2;
        }
        //构建线段树//index当前位置下标//l左边界，r右边界[l,r]
        public void buildSegmentTree(int index,int l,int r){
            if(l==r){
                tree[index]=data[l];
                return ;
            }
            int left=leftChild(index);//根据index得到左孩子的索引赋给left
            int right=rightChild(index);//根据index得到右孩子的索引赋给right
            int mid=l+(r-l)/2;//中间边界   [left,right]
            //构建左孩子的区间
            buildSegmentTree(left,l,mid);//[index,l,r]
            //构建右孩子的区间
            buildSegmentTree(right,mid+1,r);//[index,l,r]
            //求和
            tree[index]=Math.min(tree[left],tree[right]);
        }
    }




















    public int[] sortArrayByParity(int[] nums) {
        int left = 0, right = nums.length-1;
        while(left < right){
            if (nums[left] % 2 == 0){
                while(nums[left] % 2 == 0){
                    if (left < nums.length - 1)
                        left++;
                    else
                        break;
                }
            }

            if (nums[right] % 2 == 1){
                while(nums[right] % 2 == 1){
                    if (right > 0)
                        right--;
                    else
                        break;
                }
            }
            if (left < right){
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                ++left;
                --right;
            }
        }

        return nums;
    }
}
